﻿<UserControl x:Class="Coding4Fun.AppsListControl.PublisherAppsControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:AppsListControl="clr-namespace:Coding4Fun.AppsListControl"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    mc:Ignorable="d" d:DesignHeight="480" d:DesignWidth="480">
    
    <UserControl.Resources>
        <DataTemplate x:Key="AppTemplate">
            <Grid x:Name="LayoutRoot" Margin="0,0,0,4" Width="450" Background="Transparent">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="95"/>
                    <ColumnDefinition Width="1*" />
                </Grid.ColumnDefinitions>

                <Image Source="{Binding PrimaryImageUrl}" Margin="0,0,20,10" />
                <StackPanel Grid.Column="1">
                    <TextBlock Text="{Binding Title}" />
                    <AppsListControl:RatingControl Max="5" Total="{Binding UserRatingCount}" Score="{Binding AverageUserRating}" />
                    <TextBlock Text="{Binding DisplayPrice}" />
                </StackPanel>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid>
    	<VisualStateManager.VisualStateGroups>
    		<VisualStateGroup x:Name="VisualStateGroup">
    			<VisualState x:Name="Error">
    				<Storyboard>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ErrorView">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<Visibility>Visible</Visibility>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="listBox">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<Visibility>Collapsed</Visibility>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    			<VisualState x:Name="Loading">
    				<Storyboard>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="LoadingView">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<Visibility>Visible</Visibility>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="listBox">
    						<DiscreteObjectKeyFrame KeyTime="0">
    							<DiscreteObjectKeyFrame.Value>
    								<Visibility>Collapsed</Visibility>
    							</DiscreteObjectKeyFrame.Value>
    						</DiscreteObjectKeyFrame>
    					</ObjectAnimationUsingKeyFrames>
    				</Storyboard>
    			</VisualState>
    			<VisualState x:Name="Normal"/>
    		</VisualStateGroup>
    	</VisualStateManager.VisualStateGroups>
		<ListBox x:Name="listBox" ItemsSource="{Binding Apps}" ItemTemplate="{StaticResource AppTemplate}" SelectionChanged="ListBox_SelectionChanged" />
		<StackPanel x:Name="LoadingView" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Collapsed">
            <TextBlock TextWrapping="Wrap" Text="Loading list of apps..." d:LayoutOverrides="Height" FontWeight="Black"/>
			<ProgressBar Margin="0,0,0,6" Height="5" IsIndeterminate="True"/>
		</StackPanel>
		<StackPanel x:Name="ErrorView" Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center" Visibility="Collapsed">
            <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Sorry, there was an error reading the list of apps." FontStyle="Italic"/>
		</StackPanel>
	</Grid>
</UserControl>
